import { defineStore } from 'pinia'
import { ref } from 'vue'
// types
import type { LeftBarState } from '@/types/leftBar/index.ts'
// util
import { getSideBarState, setSideBarState as _setSideBarState } from '@/utils/storage.ts'

export const useLeftBarStore = defineStore('leftBar', () => {
  const sideBarState = ref<LeftBarState>(getSideBarState() as LeftBarState)
  const setSideBarState = (state: LeftBarState): void => {
    sideBarState.value = state
    _setSideBarState(state)
  }
  if (sideBarState.value === null) {
    setSideBarState('close')
  }

  return {
    sideBarState,
    setSideBarState,
  }
})
